package com.ruding.disruptor.demo;

import com.alibaba.fastjson.JSON;
import com.lmax.disruptor.EventHandler;
import com.lmax.disruptor.SleepingWaitStrategy;
import com.lmax.disruptor.WorkHandler;

//消费者实现EventHandler接口
public class LongEventHandler implements EventHandler<LongEvent>, WorkHandler<LongEvent>{
	
	private int t;
	
	
	public LongEventHandler(int t) {
		this.t = t;
	}

	//event为从RingBuffer entry中读取的事件内容，消费者从event中读取数据，并完成业务逻辑处理
	public void onEvent(LongEvent event, long sequence, boolean endOfBatch)
	{
		try {
			Thread.sleep(1000);
		} catch (InterruptedException e) {
		}
		System.out.println(Thread.currentThread().getName() + " "+this.t+" process LONG Event: " + JSON.toJSONString(event));
	}

	public void onEvent(LongEvent event) throws Exception {
		try {
			Thread.sleep(1000);
		} catch (InterruptedException e) {
		}
		System.out.println(Thread.currentThread().getName() + " "+this.t+" process LONG Event: " + JSON.toJSONString(event));
	}
}
